package com.mmx.service.impl;


import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.mmx.domain.entity.FlowInstance;
import com.mmx.mapper.FlowInstanceMapper;
import com.mmx.service.InstanceService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @desc: 流程实例接口
 * @author: liushuai
 * @date: 2023/2/8 14:29
 */
@Service
public class InstanceServiceImpl implements InstanceService {
    @Resource
    private FlowInstanceMapper flowInstanceMapper;


    public FlowInstance insertInstance(FlowInstance flowInstance){
        if(ObjectUtil.isNull(flowInstance)){
            throw new IllegalArgumentException("流程实例不能为空");
        }
        if(StrUtil.isEmpty(flowInstance.getBusinessId())){
            throw new IllegalArgumentException("业务ID不能为空");
        }
        if(ObjectUtil.isNull(flowInstance.getDefinitionId())){
            throw new IllegalArgumentException("流程定义ID不能为空");
        }
        if(ObjectUtil.isNull(flowInstance.getDefinitionKey())){
            throw new IllegalArgumentException("流程定义Key不能为空");
        }
        if (StrUtil.isEmpty(flowInstance.getInstanceName())){
            flowInstance.setInstanceName("flow");
        }
        flowInstance.setCreateTime(new Date());
        flowInstanceMapper.insertInstance(flowInstance);
        return  flowInstance;

    }


}
